package com.company.book_store.dao;

import com.company.book_store.pojo.Admin;
import com.company.book_store.util.MD5Utils;
import com.company.book_store.util.jdbcutils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class AdmindaoImpl implements Iadmindao{
    private Connection con=null;
    @Override
    public Admin selectByadnandpsw(Admin admin) {
        con= jdbcutils.getConnection();
        String sql="select * from admin where adminname=? and password=?";
        PreparedStatement pst=null;
        ResultSet set=null;
        try {
            pst=con.prepareStatement(sql);
            pst.setString(1,admin.getAdminname());
            pst.setString(2, MD5Utils.stringToMD5(admin.getPassword()));
            set=pst.executeQuery();
            Admin admin1=null;
            if(set.next())
            {
                String adminname=set.getString("adminname");
                String password=set.getString("password");
                admin1=new Admin(adminname,password);
            }
            return admin1;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }

}
